package com.manolo.client.form;

import java.awt.Rectangle;
import javax.swing.JTextArea;
import java.awt.Dimension;
import java.awt.Point;

import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

import com.manolo.framework.connection.client.ClientMultiplayer;
import com.manolo.framework.connection.entity.Message;
import com.manolo.framework.connection.entity.Player;
import com.manolo.framework.listener.dispatcher.DateDispatcher;
import com.manolo.framework.listener.event.DateEvent;
/**
 * Example of components laid out in a grid
 */
public class MessageWindow extends javax.swing.JFrame {
	private Player player = new Player();
	private javax.swing.JPanel ivjJFrameContentPane = null;
	private JTextArea jTextArea = null;
	private JTextField jtxtMsg = null;
	private JButton jbtnSend = null;
	public MessageWindow() {
		super();
		initialize();
	}
	
	public void showWindow(Player player){
		this.player = player;
		super.show();
	}
	
	/**
	 * Return the JFrameContentPane property value.
	 * @return javax.swing.JPanel
	 */
	private javax.swing.JPanel getJFrameContentPane() {
		if (ivjJFrameContentPane == null) {
			ivjJFrameContentPane = new javax.swing.JPanel();
			ivjJFrameContentPane.setName("JFrameContentPane");
			ivjJFrameContentPane.setLayout(null);
			ivjJFrameContentPane.add(getJTextArea(), null);
			ivjJFrameContentPane.add(getJtxtMsg(), null);
			ivjJFrameContentPane.add(getJbtnSend(), null);
		}
		return ivjJFrameContentPane;
	}

	/**
	 * Initialize the class.
	 */
	private void initialize() {

		this.setName("JFrame1");
		this.setSize(new Dimension(600, 500));
		this.setLocation(new Point(45, 25));
		this.setPreferredSize(new Dimension(500, 500));
		this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		this.setTitle("Messages");
		this.setContentPane(getJFrameContentPane());

	}

	/**
	 * This method initializes jTextArea	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	public JTextArea getJTextArea() {
		if (jTextArea == null) {
			jTextArea = new JTextArea();
			jTextArea.setBounds(new Rectangle(10, 9, 573, 420));
		}
		return jTextArea;
	}

	/**
	 * This method initializes jtxtMsg	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	public JTextField getJtxtMsg() {
		if (jtxtMsg == null) {
			jtxtMsg = new JTextField();
			jtxtMsg.setBounds(new Rectangle(11, 439, 488, 26));
		}
		return jtxtMsg;
	}

	/**
	 * This method initializes jbtnSend	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJbtnSend() {
		if (jbtnSend == null) {
			jbtnSend = new JButton();
			jbtnSend.setBounds(new Rectangle(507, 438, 76, 26));
			jbtnSend.setText("Send");
			jbtnSend.addMouseListener(new java.awt.event.MouseListener() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
//					player.getMessages().add(new Message(0, 1, "Teste","teste123"));
					DateEvent event = new DateEvent();
					event.getMessages().add(new Message(0, 1, "Teste",getJtxtMsg().getText()));
					DateDispatcher.getInstance().dispatchDateEvent(event);
			
					getJTextArea().setText(getJTextArea().getText() + "\n" + getJtxtMsg().getText());
				}
				public void mousePressed(java.awt.event.MouseEvent e) {
				}
				public void mouseReleased(java.awt.event.MouseEvent e) {
				}
				public void mouseEntered(java.awt.event.MouseEvent e) {
				}
				public void mouseExited(java.awt.event.MouseEvent e) {
				}
			});
		}
		return jbtnSend;
	}
}
